// 运行结果：
// Using ConcreteProduct1
// Using ConcreteProduct2
public abstract class AbstractProduct {
    public abstract void use();
}
public class ConcreteProduct1 extends AbstractProduct {
    @Override
    public void use() {
        System.out.println("Using ConcreteProduct1");
    }
}
public class ConcreteProduct2 extends AbstractProduct {
    @Override
    public void use() {
        System.out.println("Using ConcreteProduct2");
    }
}
public abstract class AbstractFactory {
    public abstract AbstractProduct factoryMethod();
}
public class ConcreteFactory1 extends AbstractFactory {
    @Override
    public AbstractProduct factoryMethod() {
        return new ConcreteProduct1();
    }
}
public class ConcreteFactory2 extends AbstractFactory {
    @Override
    public AbstractProduct factoryMethod() {
        return new ConcreteProduct2();
    }
}
public class Client {
    public static void main(String[] args) {
        AbstractFactory factory1 = new ConcreteFactory1();
        AbstractProduct product1 = factory1.factoryMethod();
        product1.use();

        AbstractFactory factory2 = new ConcreteFactory2();
        AbstractProduct product2 = factory2.factoryMethod();
        product2.use();
    }
}